using System;
using ProjectEuler.Core;

namespace ProjectEuler.UI
{
    public class Problem
    {
        public Problem(Type problemClass)
        {
            ProblemClass = problemClass;
        }

        private Type ProblemClass { get; set; }

        private IProjectEulerProblem _problemInstance;
        public IProjectEulerProblem ProblemInstance
        {
            get
            {
                // use reflection to create a new instance if necessary
                if(_problemInstance == null)
                {
                    _problemInstance = (IProjectEulerProblem) Activator.CreateInstance(ProblemClass);
                }
                return _problemInstance;
            }
        }
        
        public override string ToString()
        {
            return "Problem " + ProblemInstance.Number;
        }
    }
}